#pragma once

#include "Object/Object.h"
#include "Math/Vec3.h"
#include "Math/Quat.h"
#include "SceneNodeComponent.m.h"

class RSceneNode;
class RScene;
class CRenderScene;

RCLASS(ExtraHeader=["Scene.h"])
class WHENGINE_API RSceneNodeComponent:public RObject
{
    ROBJECT
public:
    RSceneNodeComponent();

    RFUNCTION()
    TSharedObjectPtr<RSceneNode> GetNode();

    RFUNCTION()
    TSharedObjectPtr<RScene> GetScene();    

    void BeginPlay() 
    {
        if(bAutoBeginPlay && ! bPlaying)
        {
            OnBeginPlay();
            bPlaying=true;
        }
    }
    void EndPlay()
    {
        if(IsPlaying())
        {
            OnEndPlay();
            bPlaying=false;
        }
    }
    void Tick(float DeltaSeconds) 
    {
        if(bPlaying)
        {
            OnTick(DeltaSeconds);
        }
    };

    virtual void Paint(CRenderScene* InRenderData) {};

    //auto active component when component begin play 
    RFIELD() 
    bool bAutoBeginPlay=true;

    virtual bool IsPlaying() { return bPlaying; };

    SVec3 GetWorldPosition() ;
    SQuat GetWorldRotation() ;

    void SetWorldPosition(const SVec3& InPosition);
    void SetWorldRotation(const SQuat& InRotation);
protected:    
    //RFIELD()
    bool bPlaying=false;

    virtual void OnBeginPlay() {};
    virtual void OnEndPlay() {};
    virtual void OnTick(float DeltaSeconds) {};
};